import * as types from '../mutation-types'

const state = {
  passwordVisible: 'eye-disabled',
  passwordInputType: 'password'
}

const getters = {
  passwordVisible: (state) => state.passwordVisible,
  passwordInputType: (state) => state.passwordInputType
}

const actions = {
  changeEye ({commit}) {
    commit([types.CHANGE_PASSWORD_VISIBLE])
  }
}

const mutations = {
  CHANGE_PASSWORD_VISIBLE (state, {passwordVisible, passwordInputType} = state) {
    if (passwordVisible === 'eye-disabled') {
      state.passwordVisible = 'eye'
      state.passwordInputType = 'text'
    } else {
      state.passwordVisible = 'eye-disabled'
      state.passwordInputType = 'password'
    }
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}
